﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MusicStore.Controllers
{
    public class StoreManagerController : Controller
    {
        // GET: StoreManager
        MusicStore.Models.MusicStoreEntities storeDB
    = new MusicStore.Models.MusicStoreEntities();
        public ActionResult Index()
        {
            var albums = storeDB.Albums.Include("Genre").Include("Artist");
            return View(albums.ToList());
        }
        public ActionResult Edit(int id)
        {
            MusicStore.Models.Album album = storeDB.Albums.Find(id);
            return View(album);
        }

        //
        // POST: /StoreManager/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                MusicStore.Models.Album album = storeDB.Albums.Find(id);
                if (this.TryUpdateModel<MusicStore.Models.Album>(album))
                {
                    return RedirectToAction("Index");
                }
                return View();
            }
            catch
            {
                return View();
            }
        }
        public ViewResult Details(int id)
        {
            MusicStore.Models.Album album = storeDB.Albums.Find(id);
            return View(album);
        }
        public ActionResult Delete(int id)
        {
            MusicStore.Models.Album album = storeDB.Albums.Find(id);
            return View(album);

        }
        //
        // POST: /StoreManager/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                MusicStore.Models.Album album = storeDB.Albums.Find(id);
                storeDB.Albums.Remove(album);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }


}
